package stu.aistar.listener;

import org.springframework.stereotype.Component;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

@WebListener
@Component
public class PathListener implements ServletContextListener {
    @Override
    public void contextInitialized(ServletContextEvent sce) {
        ServletContext application = sce.getServletContext();
        //获取上下文路径
        application.setAttribute("path",application.getContextPath());
        System.out.println("path"+application.getContextPath());
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {

    }
}